import { defineStore } from "pinia";

import {submitCategoryApi ,getcategory1DataApi,deletecategory1DataApi,
    updatacategory1DataApi,addGoodsDataApi,getGoodsDataApi,deletecategory2DataApi,
    getOrdersByShopAddressIdApi,modifyShopOrderApi} from "@/api/modules/user.js"


export const goodsInfo = defineStore("goodsInfo", {
    state: () => {
        return {
            
            category1Data:[],
            updatacategory1Data:{},
            goodsDataList:[]

        }
    },

    actions: {


        //上传用户的数据

      async  uploadGoodsCategory (data){
        // console.log(data,"上传后返回来的数据")
            let res = await submitCategoryApi(data)
         
            //    console.log(res,"上传后返回来的数据")
            return res
         
      },

    //   获取分类一的数据
      async getcategory1Data(data){
        console.log(data,"一级分类")
            let res = await getcategory1DataApi(data)
            if(res.code==200){
                this.category1Data=res.data
            }else{
                this.category1Data=[]
            }
            // console.log(res,"获取分类一的数据")
      },

    //   删除商品一的分类
      async deletecategory1Data(data){
            let res = await deletecategory1DataApi(data)
            return res
      },

    //     //   更新商品一的分类
    //     async updatecategory1Data(data){
    //         let res = await updatacategory1DataApi(data)
    //         if(res.code==200){
    //             this.updatacategory1Data = res.data
    //             return {code:200}
    //         }else{
    //             return {code:401}
    //         }
    //        console.log(res,"更新一级分类")
    //   }


    //添加商品数据的接口函数
    async addGoodsData(data){
        let res = await addGoodsDataApi(data)
        return res
    },


    //获取商品数据
    
    async getGoodsData(data){
        let res = await getGoodsDataApi(data)
        // console.log(data,"触发类没")
        if(res.code==200){
            // console.log(res,"res")
            this.goodsDataList= res.data
        }else{
            this.goodsDataList=[]
        }
    },

    //   删除商品一的分类
    async deletecategory2Data(data){
        let res = await deletecategory2DataApi(data)
        return res
  },

    // 商家获取订单数据
     async getOrdersByShopAddressId(data){
        let res = await getOrdersByShopAddressIdApi(data)
        return res
  },

   // 商家修改订单数据
    async modifyShopOrder(data){
        let res = await modifyShopOrderApi(data)
        return res
    },
  


    }

})

